package com.puzzlebazar.client.puzzleinfo;

import com.puzzlebazar.client.main.control.TabbedSubstate;
import com.puzzlebazar.client.main.view.TabbedView;
import com.puzzlebazar.client.user.UserModel;

public class MySolutionsSubstate extends TabbedSubstate {

	public static final String TAB_NAME = "My Solutions";
	public static final String STATE_NAME = "My Solutions";

	private final HistoryList historyList;

	private HistoryListView solutionListView = null;
	
	public MySolutionsSubstate( PuzzleInfoModel model, TabbedView view, PuzzleInfoController controller ) {
		super( view, controller );
		historyList = new HistoryList( UserModel.get(), model );
	}

	@Override
	public String getTabName() {
		return TAB_NAME;
	}

	@Override
	public String getStateName() {
		return STATE_NAME;
	}

	@Override
	public void enter() {
		super.enter();

		if( solutionListView == null ) {
			solutionListView = new HistoryListView( historyList, (PuzzleInfoController)controller );
		}
		historyList.setAutoRefresh( true );
		historyList.refresh();
		
		view.setMainWidget( solutionListView );
	}

	@Override
	public void exit() {
		super.exit();
		historyList.setAutoRefresh( false );
	}

	@Override
	public void release() {
		super.release();
		if( solutionListView != null )
			solutionListView.release();
		solutionListView = null;
		historyList.release();
	}
}
